﻿using OpenBlock.Block;
using OpenBlock.Core;
using OpenBlock.Entity;
using OpenBlock.Entity.Player;
using OpenBlock.Terrain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace OpenBlock.Item.Items
{
    public class BlockItem : IUsableItem
    {
        public string Name { get; private set; }
        public int MaxStackSize { get; private set; }
        /* BlockSnapshot.GetBlockIcon(ResId) */

        public BlockItem(string name, int maxStackSize = 64)
        {
            Name = name;
            MaxStackSize = maxStackSize;
        }

        public void OnUse(ItemStack stack, BlockState at, PlayerObj player, Vector3Int readyPlaceBlockPos)
        {
            //Debug.Log("Use!");
            player.PlaceBlock((BlockId)stack.Item.GetProperty("block").GetUint());
        }

        public Sprite GetIcon(ItemState state)
        {
            return GameManager.Instance.atlasManager.GetBlockItemIcon((BlockId)state.GetProperty("block").GetUint());
        }
    }
}
